<?php
/**
 * wap 2.0 修改购物袋商品数量
 */

/* 修改购物袋商品数量 */
if ($cart_id && $num)
{
	if ($num < 1){
		$num = 1;
	}
	else if ($num > 2){
		$num = 2;
	}

	/* 商品秒杀免邮活动, 检查修改数量是否>限购数量 */
	if (!empty($seckill_activity)){
		$cart_info = $mInterface->getShopCart($user_token);
		foreach ($cart_info AS $key => $val)
		{
			if ($val['cart_id'] == $cart_id)
			{
				$limit_num=getSeckActivityLimitNum($val['product_id'],$val['brand_id']);
				if ($limit_num>0 && $num >$limit_num){
					$result = array('code'=>0, 'msg'=>'购买失败，该商品限购'.$limit_num.'件');
					die(json_encode($result));
				}
				break;
			}
		}
	}

	$result = $mInterface->modifyShopCart($user_token, $cart_id, $num);

	if ($result == 'OUT_OF_BOUND' || 'NOT_SALE_FOR_THIS_AREA' == $result)
	{
		$result = array('code'=>0, 'msg'=>'库存不够，购买失败');
	}
	else if ($result == 'NO_CART_DATA')
	{
		$result = array('code'=>0, 'msg'=>'购物袋为空， 修改失败');
	}

	wap_setcookie("WAP[shop_time]", $now, 7200);

	die(json_encode($result));
}